package org.example.heterogeneous;

import org.example.heterogeneous.readData.FoursquareData;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class testCore {
    public static void main(String[] args) {
        testFastBCore();
        //testHomBCore();
    }

    public static void testHomBCoreSmallScaleFoursquareData() {
        // 输入参数
        int k = 1;
        String q = "333";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "testData.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readTSMC2014(inputFileName, regex);

        CoreCommunity coreCommunity = new CoreCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        coreCommunity.HomBCore(metaPath, q, targetType, k);
        // 将core信息写入文件
        Utils.writeFileCore(coreCommunity.getCoreGp(), coreCommunity.getNodeListGp().size(), outputFileName);
    }

    public static void testFastBCoreSmallScaleFoursquareData() {
        // 输入参数
        int k = 2;
        String q = "000";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "testData.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readTSMC2014(inputFileName, regex);

        CoreCommunity coreCommunity = new CoreCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        coreCommunity.FastBCore(metaPath, q, k);
        // 将core信息写入文件
        //Utils.writeFileCore(coreCommunity.getCoreGp(), coreCommunity.getNodeListGp().size(), outputFileName);
    }

    public static void testFastBCore() {
        // 输入参数
        int k = 20;
        String q = "748";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "dataset_ubicomp2013_checkins.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readubicomp2013(inputFileName, regex);

        CoreCommunity coreCommunity = new CoreCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        coreCommunity.FastBCore(metaPath, q, k);
        // 将core信息写入文件
        //Utils.writeFileCore(coreCommunity.getCoreGp(), coreCommunity.getNodeListGp().size(), outputFileName);
    }

    public static void testHomBCore() {
        // 输入参数
        int k = 20;
        String q = "748";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "dataset_ubicomp2013_checkins.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readubicomp2013(inputFileName, regex);

        CoreCommunity coreCommunity = new CoreCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        coreCommunity.HomBCore(metaPath, q, targetType, k);
        // 将core信息写入文件
        //Utils.writeFileCore(coreCommunity.getCoreGp(), coreCommunity.getNodeListGp().size(), outputFileName);
    }

    public static void testInput() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入k：");
        int k;
        k = scanner.nextInt();

        System.out.println("请输入要查询的顶点：");
        String q;
        q = scanner.next();

        System.out.println("请输入要查询的顶点类型（1-user，2-venue，3-venueCategory）：");
        int targetType;
        targetType = scanner.nextInt();

        System.out.println("请输入原路径（原路径为顶点类型，一行一行输入，以'#'结束）：");
        List<Integer> metaPath = new ArrayList<>();
        String str = scanner.next();
        while (!"#".equals(str)) {
            metaPath.add(Integer.parseInt(str));
            str = scanner.nextLine();
        }
        System.out.print("输入的原路径为：");
        int size = metaPath.size();
        for (int i = 0; i < size; ++i) {
            Integer path = metaPath.get(i);
            System.out.printf("%d", path);
            if (i != size - 1) {
                System.out.print("->");
            }
        }
        System.out.println();
    }

    public static void testReadFoursquareData() {
        FoursquareData foursquareData = new FoursquareData();

        String inputFileName = "./src/main/java/org/example/heterogeneous/data/testData.txt";
        String regex = "\t";
        foursquareData.readTSMC2014(inputFileName, regex);

        List<Node> nodeList = foursquareData.getNodeList();
        for (Node node : nodeList) {
            System.out.println(node.toString());
        }

        List<Edge> edgeList = foursquareData.getEdgeList();
        for (Edge edge : edgeList) {
            System.out.println(edge.getU() + "-" + edge.getV());
        }
    }
}
